<?php
// HTML 5 header
print $this->doctype('HTML5')."\n";

// get action and controller
$currentAction = Zend_Controller_Front::getInstance()->
					getRequest()->getActionName();
$currentController = Zend_Controller_Front::getInstance()->
						getRequest()->getControllerName();
$controllersForSearch = array('recipe','cocktail','index');
?>
<html lang="de-DE">
<head>
<meta charset="UTF-8">
<?php
// title
$title = 'Cocktail Rezepte vom cocktailberater';
if($this->layout()->getView()->title!='') {
	$title =  strip_tags($this->layout()->getView()->title).
				' vom cocktailberater';
}
print $this->headTitle($title)."\n";
// generator
$this->headMeta()->setName('generator', 'cocktailberater version '.
							APPLICATION_VERSION);
// robots
$this->headMeta()->setName('robots', 'index,follow');
// google verification
$this->headMeta()->setName('google-site-verification', 
						   'L3zaslftTHZhIO01_Og9b-KvBNM7mecVfIyMMcj2IdM');
print $this->headMeta();
// facebook (using name instead of property and no namespaces for now)
print '<meta name="og:title" content="'.
		str_replace(' vom cocktailberater','',$title).'" />';
// open graphy type
$type = 'website';
if($this->placeholder('type')!='') {
	$type =  $this->placeholder('type');
}
print '<meta name="og:type" content="'.$type.'" />';
print '<meta name="og:url" content="http://www.cocktailberater.de'.
		urlencode($_SERVER['REQUEST_URI']).'" />';
print '<meta name="og:site_name" content="cocktailberater" />';
// image
$image = 'http://www.cocktailberater.de/img/logo.png';
if($this->placeholder('image')!='') {
	$image =  $this->placeholder('image');
}
print '<meta name="og:image" content="'.$image.'" />';
print '<meta name="fb:admins" content="563752616" />';
print '<meta name="fb:app_id" content="111381035582024" />';
// print styles
print $this->headStyle()."\n";
// dojo
$this->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
$this->dojo()->enable();
$this->dojo()->setDjConfigOption('parseOnLoad', true);
$this->dojo()->setDjConfigOption('baseUrl', './');
$this->dojo()->addStyleSheetModule('dijit.themes.tundra');
// enable dojo with custom module (readStore), parser, and comboBox
$this->dojo()->registerModulePath('custom', '/js/custom');
$this->dojo()->requireModule('dojo.parser');
$this->dojo()->requireModule('dojox.data.QueryReadStore');
$this->dojo()->requireModule('dijit.form.ComboBox');
$this->dojo()->requireModule('custom.TestNameReadStore');
print $this->dojo()."\n";
// css style sheets
$this->headLink()->appendStylesheet($this->baseUrl().'/css/screen.css');
$this->headLink()->appendStylesheet($this->baseUrl().'/css/print.css','print');
// faveicon
$this->headLink(array('rel' => 'shortcut icon',
                      'href' => $this->baseUrl().'/favicon.ico'),
                      'PREPEND');
// feed of blog (rss & atom)
$this->headLink(array('rel' => 'alternate',
					  'type' => 'application/atom+xml',
					  'title' => 'cocktailberater.de Blog - Atom',
                      'href' => 
                      'http://blog.cocktailberater.de/feeds/posts/default'));
$this->headLink(array('rel' => 'alternate',
					  'type' => 'application/rss+xml',
					  'title' => 'cocktailberater.de Blog - RSS',
                      'href' => 
                 'http://blog.cocktailberater.de/feeds/posts/default?alt=rss'));
// image for facebook sharing
$this->headLink(array('rel' => 'image_src',
					  'type' => 'image/jpeg',
                      'href' => $image));
// print links
print $this->headLink()."\n";

/**
 * javascript for search
 */
if(in_array($currentController, $controllersForSearch)) {
	// define url for autoCompletion
	$autoCompletionUrl = array('module'=>'website','controller'=>'recipe','action'=>'index');
	$this->headScript()->appendScript("
		// configure query
		djConfig.usePlainJson=true;
		// add the possibility to submit the search by pressing the ENTER key 
		function init() {
			var readStore = new custom.TestNameReadStore({url:'".$this->url($autoCompletionUrl,'rest',true)."', requestMethod:'get'},dojo.byId('testStore'));
			var search = new dijit.form.ComboBox({store:readStore, autoComplete:false, hasDownArrow:false},dojo.byId('search'));
			dojo.connect(dojo.byId('search'), 'onkeypress', function(e) {
				dojo.byId('search_backup').value = dojo.byId('search').value;
				if (e.keyCode == dojo.keys.ENTER) {
					dojo.byId('suche_name').submit(); 
				}
			});
			dojo.connect(dojo.byId(\"search\"), 'onchange', function() {
				dojo.byId('search_backup').value = dojo.byId('search').value;	
			});
			dojo.connect(dojo.byId(\"search\"), 'onfocus', function() {
				dojo.byId('search_backup').value = dojo.byId('search').value;	
			});
		".(/*only focus the search bar at the start page*/ Zend_Controller_Front::getInstance()->getRequest()->getActionName()=='index'
			&& Zend_Controller_Front::getInstance()->getRequest()->getControllerName()=='index' ? "
			dojo.byId(\"search\").focus(); " : '')."
		}
		dojo.addOnLoad(init);");
}
/**
 * end javascript for search
 */
// print scripts
print $this->headScript()."\n";
?>
</head>
<body class="tundra">
<!-- begin: top links -->
<div id="pre-header">
<?php 
$imprintLink = array(	'module'=>'website',
						'controller'=>'portal',
						'action'=>'imprint');
$currentPageUrlEncoded = urlencode('http://www.cocktailberater.de'.
							$_SERVER['REQUEST_URI']);
?>
<ul class="no-bullet">
	<li onmouseover="dojo.byId('spr_info_gray').id='spr_info';"
		onmouseout="dojo.byId('spr_info').id='spr_info_gray';"><a
		href="<?php print $this->url($imprintLink,'default',true); ?>"> <span
		class="social_sprites" id="spr_info_gray"></span> Impressum</a></li>
	<li onmouseover="dojo.byId('spr_rss_gray').id='spr_rss';"
		onmouseout="dojo.byId('spr_rss').id='spr_rss_gray';"><a
		href="http://blog.cocktailberater.de/feeds/posts/default"
		title="Blog als RSS-Feed abonnieren"> <span class="social_sprites"
		id="spr_rss_gray"></span> Blog </a></li>
	<li onmouseover="dojo.byId('spr_mobile_gray').id='spr_mobile';"
		onmouseout="dojo.byId('spr_mobile').id='spr_mobile_gray';"><a
		href="?format=mobile"> <span class="social_sprites"
		id="spr_mobile_gray"></span> Mobile Seite</a></li>
	<li onmouseover="dojo.byId('spr_facebook_fan_gray').id='spr_facebook_fan';"
		onmouseout="dojo.byId('spr_facebook_fan').id='spr_facebook_fan_gray';">
	<a href="http://www.facebook.com/cocktailberater"
		title="auf facebook Fan werden"> <span class="social_sprites"
		id="spr_facebook_fan_gray"></span> Fan werden </a></li>
	<li	onmouseover="dojo.byId('spr_facebook_share_gray').<?php 
		?>id='spr_facebook_share';"
		onmouseout="dojo.byId('spr_facebook_share').<?php 
		?>id='spr_facebook_share_gray';">
	<a href="http://www.facebook.com/sharer.php?u=<?php 
			print $currentPageUrlEncoded; ?>&amp;t=<?php 
			print urlencode($title); ?>"
		title="auf facebook teilen"> <span class="social_sprites"
		id="spr_facebook_share_gray"></span> Teilen</a></li>
	<li onmouseover="dojo.byId('spr_twitter_gray').id='spr_twitter';"
		onmouseout="dojo.byId('spr_twitter').id='spr_twitter_gray';"><a
		href="http://twitter.com/home?status=<?php 
			print urlencode($title).':+'.$currentPageUrlEncoded; ?>"
		title="auf Twitter posten"> <span class="social_sprites"
		id="spr_twitter_gray"></span> Twittern </a></li>
	<li class="left"><a href="http://del.icio.us/post?url=<?php 
			print $currentPageUrlEncoded; ?>&amp;title=<?php 
			print urlencode($title); ?>"
		title="auf delicious bookmarken"> <span class="social_sprites"
		id="spr_delicious"></span> <span class="hide">delicious</span> </a></li>
	<li class="left"><a href="http://digg.com/submit?phase=2&amp;url=<?php 
			print $currentPageUrlEncoded; ?>&amp;title=<?php 
			print urlencode($title); ?>"
		title="auf Digg bookmarken"> <span class="social_sprites"
		id="spr_digg"></span> <span class="hide">Digg</span> </a></li>
	<li class="left"><a href="http://www.stumbleupon.com/submit?url=<?php 
			print $currentPageUrlEncoded; ?>&amp;title=<?php 
			print urlencode($title); ?>"
		title="auf StumbleUpon bookmarken"> <span class="social_sprites"
		id="spr_su"></span> <span class="hide">StumbleUpon</span> </a></li>
</ul>
</div>
<!-- end: top links -->
<!-- begin: body -->
<div id="wrapper">
	<?php
	// show full header only start page
	// check if on start page -> show big header
	if($currentAction == 'index' && $currentController == 'index') { 
		$headStyle = 'background-image: url(\''.$this->baseUrl().
					 '/img/header.png\'); height: 142px;';
		$linkStyle = 'height: 142px;';
		$homeStyle = '';
		$homeStyleHover = '';
	}
	// show small header on all other pages
	else { 
		$headStyle = 'background-image: url(\''.$this->baseUrl().
					 '/img/header-detail.png\'); height: 50px;';
		$linkStyle = 'height: 50px;'; 
		$homeStyle = '<span id="home_hover" style="position: relative; '.
					 'background: url(\''.$this->baseUrl().'/img/home.png'.
					 '\') no-repeat; height: 40px; left: 270px; top: 6px; '.
					 'display: none; width: 100px;">&nbsp;</span>';
		$homeStyleHover = ' onmouseover="document.getElementById'.
						  '(\'home_hover\').style.display=\'block\';" '.
						  'onmouseout="document.getElementById'.
						  '(\'home_hover\').style.display=\'none\';"';
	}
	?>
	<div id="header" style="<?php print $headStyle; ?>"<?php 
		print $homeStyleHover; ?>>
		<h1 style="margin: 0;"><a 
			href="/" 
			style="<?php print $linkStyle;?>"><span 
			class="hide">cocktailberater</span><?php 
			print $homeStyle; ?></a></h1>
	</div>
	<div id="homepage">
		<?php
		$controllersForBreadcrumb = array(	'portal','ingredient',
											'ingredient-category',
											'product','manufacturer');
		if(in_array($currentController, $controllersForBreadcrumb)) {
		?>
		<p class="breadcrumb">Sie sind hier: 
			<?php
			// load whole navigation structure for breadcrumb 
			// and subset for menu
			$portalNavigationConfig = new Zend_Config_Ini(APPLICATION_PATH.
						'/modules/website/config/portal-navigation.ini','nav');
			$portalNoMenuConfig = new Zend_Config_Ini(APPLICATION_PATH.
						'/modules/website/config/portal-no-menu.ini','nav');
			$breadCrumbContainer = new Zend_Navigation($portalNavigationConfig);
			$menuContainer = $breadCrumbContainer;
			$breadCrumbContainer->addPages($portalNoMenuConfig);
			
			// replace 'Zutat' in breadcrumb with specific ingredient
			if($breadCrumbContainer->findOneBy('label', 'Zutat')){
				$ingredientPage = $breadCrumbContainer->findOneBy('label', 'Zutat');
				$ingredientPage->setParams(array('id' => Zend_Controller_Front::getInstance()->getRequest()->
						getParam('id')));
				$ingredientPage->setLabel($this->placeholder('label')->toString());
			}
			// replace 'Zutatenkategorie' in breadcrumb with specific ingredient-category
			if($breadCrumbContainer->findOneBy('label', 'Zutatenkategorie')){
				$ingredientCategoryPage = $breadCrumbContainer->findOneBy('label', 'Zutatenkategorie');
				$ingredientCategoryPage->setParams(array('id' => Zend_Controller_Front::getInstance()->getRequest()->
						getParam('id')));
				$ingredientCategoryPage->setLabel($this->placeholder('label')->toString());
			}
			// replace 'Produkt' in breadcrumb with specific product
			if($breadCrumbContainer->findOneBy('label', 'Produkt')){
				$productPage = $breadCrumbContainer->findOneBy('label', 'Produkt');
				$productPage->setParams(array('id' => Zend_Controller_Front::getInstance()->getRequest()->
						getParam('id')));
				$productPage->setLabel($this->placeholder('label')->toString());
			}
			// replace '_Hersteller_' in breadcrumb with specific manufacturer
			if($breadCrumbContainer->findOneBy('label', '_Hersteller_')){
				$manufacturerPage = $breadCrumbContainer->findOneBy('label', '_Hersteller_');
				$manufacturerPage->setParams(array('id' => Zend_Controller_Front::getInstance()->getRequest()->
						getParam('id')));
				$manufacturerPage->setLabel($this->placeholder('label')->toString());
			}
			// print breadcrumb with specific resource format
			print $this->navigation($breadCrumbContainer)->breadcrumbs()->
					setPartial(array('template/breadcrumbs.phtml', 'website'))->
					renderPartial();
			?>
		</p>
		<?php 
		}
		if(in_array($currentController, $controllersForSearch)) { 
			require_once 'template/search.phtml'; 
		}
		?>		
		<div id="content"><?php print $this->layout()->content ?></div>
		<?php 
		// render menu for $controllersForBreadcrumb pages
		if(in_array($currentController, $controllersForBreadcrumb)) {
			?><div class="sub_nav"><?php 
			// select subpart of menu container to render
			$communityPages = $this->navigation($menuContainer)->
							findOneByLabel('Portal');
			print $this->navigation($menuContainer)->menu()->
				renderPartial($communityPages, 'template/portal_nav.phtml');
			?></div><?php 
		}
		?>
	</div>
	<!-- insert clearing div to make border appear on the bottom -->
	<div class="clear"></div>
</div>
<!-- end: body -->
<?php if(APPLICATION_ENV=='production') { ?>
<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://stats.thobach.de/" : "http://stats.thobach.de/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 4);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://stats.thobach.de/piwik.php?idsite=4" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tag -->
<?php } ?>
</body>
</html>
<!-- layout.html.phtml -->